﻿using Jw.Core;
using Jw.Models;
using Jw.Web.Areas.Weight.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;

namespace Jw.Web.Areas.Weight.Controllers
{
    public class CastingController : Controller
    {
        //
        // GET: /Weight/Material/
        public List<dynamic> GetPaiHaoItems()
        {
            var result = new List<dynamic>();
            result.Add(new { value = "Al99.90", text = "Al99.90" });
            result.Add(new { value = "Al99.85", text = "Al99.85" });
            result.Add(new { value = "Al99.80", text = "Al99.80" });
            result.Add(new { value = "Al99.70", text = "Al99.70" });
            result.Add(new { value = "Al99.60", text = "Al99.60" });
            result.Add(new { value = "Al99.50", text = "Al99.50" });
            result.Add(new { value = "等外", text = "等外" });
            return result;
        }

        public List<dynamic> JGitems()
        {
            var result = new List<dynamic>();
            result.Add(new { value = "合格", text = "合格" });
            result.Add(new { value = "波纹", text = "波纹" });
            return result;
        }

        public ActionResult Index()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "S_TM", //主键
                urls = new
                {
                    query = "/api/Weight/Casting/"
                },
                resx = CastingHelper.GetIndexResx("铸造检斤"),
                dataSource = new
                {
                    GetPaiHaoItems = GetPaiHaoItems(),
                    JGitems = JGitems()
                },
                form = new
                {
                    S_TM = "",
                    S_SCXH = "",
                    S_PH = "",
                    D_ZZMZSJ = "",
                    S_ZJJG = "",
                    S_BCDM = ""
                }
            };
            return View(model);
        }
    }

    public class CastingApiController : ApiController
    {

        public dynamic Get(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='S_TM DESC'>
            <select>a.*,b.S_BZMC,c.S_BCMC,d.S_JLQXMC,e.S_YHMC as S_JLYMC,f.S_YHMC as S_ZJYMC,g.S_YHMC as S_XZZMC</select>
                <from>JJ_ZZCPDBRKJJ a left join PT_BMCJBZSZ b on a.S_BZDM =b.S_BZDM 
                                      left join PT_BCSZ c on a.S_BCDM =c.S_BCDM
                                      left join JJ_JLQX d on a.S_ZZQXDM=d.S_JLQXDM
                                      left join dbo.PT_YHXX e on a.S_JLY=e.S_YHDM
                                      left join dbo.PT_YHXX f on a.S_ZJY=f.S_YHDM
                                      left join dbo.PT_YHXX g on a.S_DBBZ=g.S_YHDM

                </from>
                    <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                        <field name='S_TM' cp='like'></field>
                        <field name='S_SCXH' cp='like'></field>
                        <field name='S_PH' cp='like'></field>
                        <field name='D_ZZMZSJ' cp='daterange'></field>
                        <field name='S_ZJJG' cp='like'></field>
                        <field name='S_BCDM' cp='like'></field>
                    </where>
            </settings>");
            var service = new JJ_ZZCPDBRKJJService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);

            return result;
        }

    }

}